package cn.tedu.boot421.controller;

import cn.tedu.boot421.mapper.UserMapper;
import cn.tedu.boot421.vo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired(required = false)
    UserMapper mapper;
    @RequestMapping("/check")
    public int check(String username){
        User user = mapper.selectByUsername(username);
        return user==null?1:2;
    }
    @RequestMapping("/reg")
    public int reg(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            return 2;
        }
        mapper.insert(user);
        return 1;
    }
    @RequestMapping("/login")
    public int login(User user){
        User u = mapper.selectByUsername(user.getUsername());
        if (u!=null){
            if (u.getPassword().equals(user.getPassword())){
                return 1;
            }
            return 2;
        }
        return 3;
    }
}
